package com.pro_one.service.impl;

import com.pro_one.dao.MemberEditDao;
import com.pro_one.pojo.Member;
import com.pro_one.pojo.Setmeal;
import com.pro_one.service.MemberEditService;
import com.pro_one.service.MemberService;
import com.pro_one.util.DateUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = MemberEditService.class)
@Transactional
public class MemeberEditServiceImpl implements MemberEditService {
    @Autowired
    private MemberEditDao memberEditDao;

    @Override
    public Member findByOldtelephone(String logintelephone) {

        return memberEditDao.findByOldtelephone(logintelephone);
    }

    @Override
    public void updateWXMember(Map map) {
        String birthday = (String) map.get("birthday");
        try {
            Date date = DateUtils.parseString2Date(birthday);
            map.put("birthday", date);
            memberEditDao.updateWXMember(map);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public List<Map<String,Object>> findsetmealByDate(List list) {
        String logintelephone = (String) list.get(0);
        System.out.println(logintelephone);
        Date starttime = null;
        try {
            starttime = DateUtils.parseString2Date((String) list.get(1));
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(starttime);
        Date endtime = null;
        try {
            endtime = DateUtils.parseString2Date((String) list.get(2));
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(endtime);
        Map<String,Object> map=new HashMap<>();
        map.put("logintelephone",logintelephone);
        map.put("starttime",starttime);
        map.put("endtime",endtime);

        List<Map<String,Object>> setmealList = memberEditDao.findsetmealByDate(map);
        /*String memberName = memberEditDao.findMemberIDBytelephone(logintelephone);
        Map<String,List<Member>> map1=new HashMap<>();
        map1.put("memberName",memberName);*/
        return setmealList;
    }
}
